<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('admin')) {
            Schema::create('admin', function (Blueprint $table) {
                $table->increments('id')->comment('主键ID');
                $table->string('account', 32)->default('')->comment('账号');
                $table->string('password', 128)->default('')->comment('密码');
                $table->string('avatar', 128)->default('')->comment('头像');
                $table->string('name', 32)->default('')->comment('姓名');
                $table->string('email', 128)->default('')->comment('邮箱');
                $table->string('phone', 32)->default('')->comment('手机号');
                $table->string('last_ip', 16)->default('')->comment('最后一次登录ip');
                $table->datetime('last_time')->nullable()->comment('最后一次登录时间');
                $table->tinyInteger('is_super')->default(2)->comment('是否超级管理员（1：是，2：否）');
                $table->tinyInteger('status')->default(1)->comment('状态（1：开启，2：禁用）');
                $table->datetime('created_at')->nullable()->useCurrent()->comment('创建时间');
                $table->datetime('updated_at')->nullable()->useCurrent()->useCurrentOnUpdate()->comment('更新时间');
                $table->datetime('deleted_at')->nullable()->comment('删除时间');
            });
            DB::statement(sprintf("ALTER TABLE `%s%s` comment '%s'", config('database.connections.mysql.prefix'), 'admin', '后台管理员表'));
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin');
    }
};
